<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page contentType="text/html; charset=utf-8"%>
<%@page import="com.yc.comm.Constant"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<html>
<head>
    <base href="<%=basePath%>">
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">  
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	
	<script type='text/javascript' src='/btsm/dwr/interface/JTaskWeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/interface/JCommWeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/interface/JGeographicalenvWeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/engine.js'></script>
	<script type='text/javascript' src='/btsm/dwr/util.js'></script>	 	
  </head>
<body>
	 <div id="stationContent" style="height:80%"></div>
	 <div id="sectionContent" style="height:80%"></div>
	 <div id="taskContent" style="width:100%;height:100%"></div>   

<script type="text/javascript">
var ds;
Ext.onReady(function(){
	Ext.QuickTips.init(); 
	Ext.form.Field.prototype.msgTarget = 'side'; 
	
	new Ext.Viewport({
	    layout:'border',
	    frame:true,
	    items:[	    	
	    	{	region: 'center',
		        contentEl: 'taskContent',
		        margins:'110 5 30 5',
				split: true,
				border: true	
		    }]
		});
	
	var sm = new Ext.grid.CheckboxSelectionModel({singleSelect: true});	
	var recordType = Ext.data.Record.create([								
							   {name: 'id', type: "string"},
							   {name: 'tasktype', type: "string"},//任务类型
							   {name: 'acode', type: "string"},//中继段编码
							   {name: 'aname', type: "string"},//中继段名称
							   {name: 'lng', type: "string"},
							   {name: 'lat', type: "string"},
							   {name: 'alt', type: "string"},
							   {name: 'memo', type: "string"},
							   {name: 'userid', type: "string"},
							   {name: 'pmuid', type: "string"},
							   {name: 'rdtime', type: "date"},
							   {name: 'proceddtime', type: "date"},
							   {name: 'status', type: "string"}
						 ]);
	var cm  = new Ext.grid.ColumnModel(
			[
				sm,            
				{header: "流水号", width: 80, sortable: true, dataIndex: 'id',align:'left'},
				{header: "任务类型", width: 140, sortable: true, dataIndex: 'tasktype',align:'left'},
				{header: "中继段名称", width: 140, sortable: true, dataIndex: 'aname',align:'left'},	
				{header: "任务状态", width: 140, sortable: true, dataIndex: 'status',align:'left',renderer: formatStatus}, 
				{header: "处理时间", width: 140, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d'),dataIndex: 'proceddtime',align:'left'}, 				
				{header: "删除", width: 50, sortable: false, dataIndex: 'id',renderer: showDelete}				
			]
		);
	
	function formatStatus(value) 
	{
		var strState = "";
		if(value == "1"){
			//strState = '<span style="color:red;">' + "否" + '</span>';
			strState = '<span style="color:blue;">' + "待分配" + '</span>';
		}else if(value == "3"){
			strState = '<span style="color:red;">' + "待处理" + '</span>';
		}else if(value == "4"){
			strState = '<span style="color:black;">' + "已处理" + '</span>';
		}	
		return strState;
	}
	
	
	function showDelete(id)
	{
		return "<input type='button' value='删除' class='x-btn button' onclick='doDeleteDict(\"" + id  +   "\")'>";  
	}
	
	ds = new Ext.data.Store({
		proxy: new Ext.data.DWRProxy(JTaskWeb.allTasks, true),	
		reader: new Ext.data.ListRangeReader({
			totalProperty: 'totalSize',
			id: 'id'
		}, recordType),
		sortInfo:{field:'id', direction:'ASC'}// 排序信息
	});	
	
	
	function createTask(){
		var data = {};
		var record = new Ext.data.Record(data);
		taskWindow.show();
		taskWindow.formPanel.getForm().loadRecord(record);
	}
	function editTask(){
		
	}
	
	var btnAdd = new  Ext.Button({
			text:'新建',
			pressed:true,					 
			handler:createTask
		});
	var btnEdit = new  Ext.Button({
			text:'分配',
			pressed:true,					 
			handler:editTask
		});	
	
	var contentDiv = Ext.get("taskContent");
	var grid = new Ext.grid.GridPanel({
	    	el: 'taskContent',	    	
	        ds: ds,
	        cm: cm,
			sm:sm,
			//title: '字典列表',
		    width: contentDiv.getComputedWidth(),
			height: contentDiv.getComputedHeight(), 
	        frame:true,
	        collapsible:false, 
	        enableDragDrop:false, 
	        tbar: [
					btnAdd,
					'-',
					btnEdit
				],
			bbar: new Ext.PagingToolbar({
			        pageSize: 15,
			        store: ds,
			        displayInfo: true,
			        displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
			        emptyMsg: "没有记录"
			    })
					
				
	    });
	    
	
    grid.render(); 
	ds.load({params:{start:0,limit:15}});	
	
		
	//选择基站弹出窗口
	
		
	function doShow()
	{	        
		//stationWin.show();	
		//loadBtsCodeDate(cDS);	
		//statgrid.render(); 
		//statds.load({params:{start:0,limit:17}});
		 	
	}
	
	
	var taskTypeStore  = new Ext.data.Store({  
        proxy:new Ext.data.DWRProxy(JCommWeb.getDirctoryByType,{}),  
        reader:new Ext.data.DWRArrayReader(
				{},
				new Ext.data.Record.create([  
					{name: 'text', mapping:1},       
					{name: 'value',mapping:0}                   
				  ])
				)  
    });
	var taskTypeCombo = new Ext.form.ComboBox({	   
		fieldLabel: '任务类型',
		name: 'tasktype',	
		width:200,
		valueField :"value",
		displayField: "text",
		mode: 'remote',
		selectOnFocus:true,                    
		forceSelection: true,
		blankText:'任务类型',
		emptyText:'任务类型',
		hiddenName:'tasktype',
		triggerAction: 'all',
		editable:false, 
		store: taskTypeStore
		});
	taskTypeStore.on('beforeload', function() {
		taskTypeStore.baseParams = {
				DIRECTORY_TYPE:'39'   
		  };
	});	
	
	
	var taskForm = new Ext.FormPanel({
    	labelAlign: 'right',
        frame:true,	        
        labelWidth:80,	       
		anchor:'90%',
		height:550,		
		buttonAlign:'right', 
		border: false,
		layout:'column',
		margins:'35 35 35 35',	
        items: [ 
				{
					columnWidth:.50,
					layout: 'form',  
					labelWidth:100,	 
					labelAlign:'right',		
					items: [
							{
								xtype:'textfield',
								fieldLabel: '任务名称',
								width:200,
								name: 'taskname'
							},
							taskTypeCombo
					        ]
				},{
					columnWidth:.50,
					layout: 'form',  
					labelWidth:100,	 
					labelAlign:'right',		
					items: [{
								xtype:'textarea',
								fieldLabel: '备注',
								width:200,
								name: 'memo'
							}
                			]
				}]
	});
	
	
	var TaskWindow = function() {
		var _win = this;
		this.formPanel = taskForm;
		var _form = this.formPanel.getForm();
		TaskWindow.superclass.constructor.call(this, { 
			title: '创建任务',
			width : 980,
			height : 350,
			resizable : true,
			plain : false,
			border : false,
			modal : true,
			autoScroll : false,
			layout : 'fit',
			closeAction : 'hide',
			items : this.formPanel,
			buttonAlign:'center',
			buttons : 
			[
				{	
					text : ' 保存',
					handler :  function(){
						if (!_form.isValid())
							return;	
							
						 
					
					}
				},{
					text : '取消',
					handler : function() {
						_win.hide();
						_form.reset();
					},
					tooltip : '关闭对话框'
				}
			]	
		});
	};
	Ext.extend(TaskWindow, Ext.Window); 
	var taskWindow = new TaskWindow();	
	
	
	
});

function doDeleteDict(id){
	Ext.MessageBox.confirm('确认', '确认要删除?', 
		function(btn) {
		 if(btn == 'yes') // 选中了是按钮	
		 {   	
			JTaskWeb.deleteTask(id, function(data) {
				 if(data) {					    	     		
					 ds.load({params:{start:0,limit:15}});
				 }else 
				 {
					Ext.Msg.alert("操作失败"," 删除字典操作失败!");
				 }
			 });
			
		 }
	});
}



</script>
	 
</body>
</html>